<!--二级多选功能-->
<template>
  <div>
    <two-check-item v-for="(group,index) in data" :key="index" :node="group" @check="check"/>
  </div>
</template>

<script>
import TwoCheckItem from './TwoCheckItem';

export default {
  name: 'TwoCheck',
  components: { TwoCheckItem },
  props: {
    data: {
      type: Array,
      default: () => []
    },
    // eslint-disable-next-line
    value: {},
    // eslint-disable-next-line vue/require-prop-types
    props: {
      default() {
        return {
          children: 'children',
          id: 'id',
          label: 'label',
          disabled: 'disabled'
        };
      }
    }
  },
  data() {
    return {
      // 每个分组的选择的ID
      checkById: {}
    };
  },
  methods: {
    check(id, value) {
      this.checkById[id] = value;
      this.change();
    },
    change() {
      var ids = [];
      for (const checkByIdKey in this.checkById) {
        ids = ids.concat(this.checkById[checkByIdKey]);
      }
      this.$emit('change', ids);
    }
  }
};
</script>

<style scoped>

</style>
